let fs = require('fs');
let createFile = {
    createPath: function (dir) {
        //文件可能存在
        if (fs.existsSync(dir)) {
            return;
        }
        fs.mkdirSync(dir);
    },
    //创建内容
    createContent: function (num) {
        return num+'';

    },
    //写入文件与内容
    createFile:function (filePath,content) {
        console.log(filePath);
        let fd = fs.openSync(filePath,'w');
        fs.writeSync(fd,content);
        fs.closeSync(fd);
    },

    handle:function(num,dir) {
        //目标不存在则创建
      this.createPath(dir);
        //循环创建文件与内容
        for(let i = 1;i < num;i++) {
            let fileName = dir+'/'+i+'.txt';   //进一步抽离
            let content = this.createContent(i);
            this.createFile(fileName,content);
        }   
    }
}
createFile.handle(10,'./demo01')